package org.techmore.common.utils.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.util.DisplayMetrics;
import android.view.Window;

public class ActivityUtils {
	
	private static ActivityUtils activityTransitionUtils = new ActivityUtils();

	public static ActivityUtils getInstance() {
		return activityTransitionUtils;
	}
	
	
	public void leftIN_rightOUT_Transition(Activity activity,Context context,Class<?> targetClass){
		
		activity.startActivity(new Intent(context,targetClass));
		
//		if(activity.getWindowManager().getDefaultDisplay().getRotation()==0){
			activity.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
//		}else{
//			activity.overridePendingTransition(android.R.anim.fade_out, android.R.anim.fade_in);
//		}
	}
	
	public void leftIN_rightOUT_close_Transition(Activity activity,Context context,Class<?> targetClass){
		
		activity.startActivity(new Intent(context,targetClass));
		
//		if(activity.getWindowManager().getDefaultDisplay().getRotation()==0){
			activity.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
//		}else{
//			activity.overridePendingTransition(android.R.anim.fade_out, android.R.anim.fade_in);
//		}
		activity.finish();
	}
	
	
	//自由屏
	public void setScreenOrientation(Activity activity){
    	activity.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
//		window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//		activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);	//豎屏
//    	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);		//橫屏
    }
	
//	//豎屏
	public void setPortpaitScreenOrientation(Activity activity){
    	activity.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
//		window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);	//豎屏
//    	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);		//橫屏
    }
	
	
	
	private DisplayMetrics metrics = null;
	
	private void getMetrics(Activity ac){
		metrics = new DisplayMetrics();
		ac.getWindowManager().getDefaultDisplay().getMetrics(metrics);
	}
	
	//获取屏幕宽高
	public int[] getWidthHight(Activity ac){
		getMetrics(ac);
		return new int[]{metrics.widthPixels,metrics.heightPixels};
	}

}
